from api.employee import EmployeeAPI
import unittest

from utils import comm_assert


class TestEmployee(unittest.TestCase):
    #初始化员工id
    employee_id=None

    def setUp(self):
        self.employee_api=EmployeeAPI()

    def test01_add_employee(self):
        add_employee_data = {
            "username": "zhangxiaohong011",  # 用户名唯一
            "mobile": "18800000011",  # 手机号唯一
            "timeOfEntry": "2021-09-10",
            "formOfEmployment": 1,
            "workNumber": "20210011",  # 员工ID唯一性
            "departmentName": "销售",
            "departmentId": "1266699057968001024",
            "correctionTime": "2021-08-30T16:00:00.000Z"
        }
        response=self.employee_api.add_emplayee(add_employee_data)
        print(response.json())
        # 断言
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        comm_assert(self, response, 200, True, 10000, "操作成功")

        #提取员工id
        TestEmployee.employee_id=response.json().get("data").get("id")
        print(self.employee_id)

    # 修改员工
    def test02_update_emplayee(self):
        updata_data={
            "username": "zhangxiaohong9996",  # 用户名唯一
            "mobile": "18800009996",  # 手机号唯一
            "timeOfEntry": "2021-09-10",
            "formOfEmployment": 1,
            "workNumber": "20219996",  # 员工ID唯一性
            "departmentName": "技术",
            "departmentId": "1266699057968001024",
            "correctionTime": "2021-08-30T16:00:00.000Z"
        }
        print(self.employee_id)
        response=self.employee_api.update_emplayee(updata_employee_data=updata_data,employee_id=self.employee_id)
        print(response.json())
        comm_assert(self, response, 200, True, 10000, "操作成功")

    # 查询员工
    def test03_get_employee(self):
        print(self.employee_id)
        response=self.employee_api.get_employee(self.employee_id)
        print(response.json())
        comm_assert(self, response, 200, True, 10000, "操作成功")

    # 删除员工
    def test04_delete_employee(self):
        print(self.employee_id)
        response=self.employee_api.delete_employee(employee_id=self.employee_id)
        print(response.json())
        comm_assert(self, response, 200, True, 10000, "操作成功")



